#encoding: utf-8

class JillionStocksController < ApplicationController
  # GET /jillion_stocks
  # GET /jillion_stocks.xml
  def index
    @jillion_stocks = JillionStock.all
    respond_to do |format|
      format.html {return 'index'}# index.html.erb
      format.xml { render :xml => @jillion_stocks }
    end
  end

  # GET /jillion_stocks/1
  # GET /jillion_stocks/1.xml
  def show
    @jillion_stock = JillionStock.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml { render :xml => @jillion_stock }
    end
  end

  def analyse
    @jillion_stock = JillionStock.find(params[:id])
    @jillion_stock.analyse
  end

  # GET /jillion_stocks/new
  # GET /jillion_stocks/new.xml
  def new
    @jillion_stock = JillionStock.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml { render :xml => @jillion_stock }
    end
  end

  # GET /jillion_stocks/1/edit
  def edit
    @jillion_stock = JillionStock.find(params[:id])
  end

  # POST /jillion_stocks
  # POST /jillion_stocks.xml
  def create
    @jillion_stock = JillionStock.new
    @jillion_stock.id = params[:jillion_stock][:stock_id]
    if @jillion_stock.save
      redirect_to(:action => index, :notice => "\"#{ @jillion_stock.stock_name}\"成功添加至巨量股票池中！")
    else
      respond_to do |format|
        format.html { render :action => "new" }
        format.xml { render :xml => @jillion_stock.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /jillion_stocks/1
  # PUT /jillion_stocks/1.xml
  def update
    @jillion_stock = JillionStock.find(params[:id])

    respond_to do |format|
      if @jillion_stock.update_attributes(params[:jillion_stock])
        format.html { redirect_to(@jillion_stock, :notice => 'Jillion stock was successfully updated.') }
        format.xml { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml { render :xml => @jillion_stock.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /jillion_stocks/1
  # DELETE /jillion_stocks/1.xml
  def destroy
    @jillion_stock = JillionStock.find(params[:id])
    @jillion_stock.destroy

    respond_to do |format|
      format.html { redirect_to(jillion_stocks_url) }
      format.xml { head :ok }
    end
  end
end
